package com.common.project.exception;

import com.common.project.common.StatusCode;

/**
 * @ClassName BaseException
 * @Description
 * @Author jiangshicun@bicai365.com
 * @Date 2019/6/20 13:48
 */
public class BaseException extends RuntimeException{
    private static final long serialVersionUID = 1L;
    private StatusCode errCode;

    public BaseException() {
    }

    public BaseException(String errMessage) {
        super(errMessage);
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

    public BaseException(String errMessage, Throwable e) {
        super(errMessage, e);
    }

    public BaseException(StatusCode errCode) {
        super(String.format("%s %s", errCode.getCode(), errCode.getMessage()));
        this.errCode = errCode;
    }

    public BaseException(StatusCode errCode, String message) {
        super(String.format("%s %s %s", errCode.getCode(), errCode.getMessage(), message));
        this.errCode = errCode;
    }

    protected BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public static BaseException instance(StatusCode errorCode) {
        throw new BaseException(errorCode);
    }

    public static BaseException instance(StatusCode errorCode, String message) {
        throw new BaseException(errorCode, message);
    }

    public StatusCode getErrCode() {
        return this.errCode;
    }

    public void setErrCode(StatusCode errCode) {
        this.errCode = errCode;
    }
}
